package pcgen.android.app;

import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class FragmentEx extends Fragment 
{
	public FragmentEx()
	{
	}
	
    public abstract int getLayoutId();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle inState) 
    {
    	super.onCreateView(inflater, container, inState);
    	
    	if (inState != null)
			stateRestore(inState);
    	
    	initCreate(inflater, container, inState);
    	
    	View view = inflater.inflate(getLayoutId(), container, false);
        inflateView(view);        

        return view;
    }
    
    @Override
    public void onPause()
    {
    	super.onPause();
    	
    	initPause();
    }
    
    @Override
    public void onResume()
    {
    	super.onResume();
    	
    	initResume();
    }
	
	@Override
    public void onSaveInstanceState(Bundle outState)
	{
		if (outState != null)
			stateSave(outState);
		
		super.onSaveInstanceState(outState);
	}
    
    @Override
    public void onStart()
    {
    	super.onStart();
    	
    	initStart();
    }
    
    protected abstract void inflateView(View view);
    
    protected void initCreate(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
    }
    
    protected void initPause()
    {
    }
    
    protected void initResume()
    {
    }
    
    protected void initStart()
    {
    }
	
	protected void stateRestore(Bundle inState)
	{
	}
	
	protected void stateSave(Bundle outState)
	{
	}
}
